package com.jian.mall.produce.web;

import com.jian.mall.produce.entity.SkuSaleAttrValueEntity;
import com.jian.mall.produce.service.CategoryService;
import com.jian.mall.produce.service.SkuSaleAttrValueService;
import com.jian.mall.produce.service.SpuInfoService;
import com.jian.mall.produce.vo.SaleItemVo;
import com.jian.mall.produce.vo.json.CatalogLevel2;
import com.jian.mall.produce.vo.json.CatalogVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/produce")
public class CatalogController {
    @Autowired
    private CategoryService categoryService;
    @Autowired
    private SpuInfoService spuInfoService;
    @Autowired
    private SkuSaleAttrValueService skuSaleAttrValueService;
    @GetMapping("/index/json/catalog.json")
    @ResponseBody
    public CatalogVo<List<CatalogLevel2>> catalogJson(){
        return categoryService.getCatalogJsonVo();
    }

    @GetMapping("/item/{skuId}")
    @ResponseBody
    public SaleItemVo searchSkuItemInfo(@PathVariable("skuId")Long skuId){
        return spuInfoService.getSkuItemInfo(skuId);
    }

    /**
     * 根据skuId 获取到销售属性
     */
    @GetMapping("/attrValue/{skuId}")
    @ResponseBody
    public List<SkuSaleAttrValueEntity> attrValueBySkuId(@PathVariable("skuId") Long skuId){
        return skuSaleAttrValueService.attrValueBySkuId(skuId);
    }

    /**
     * 根据销售属性值 获取对应的skuId
     */
    @PostMapping("/attrId/SaleAttrs")
    @ResponseBody
    public Long skuIdBySaleAttrs(@RequestParam List<Long> attrSaleId){
        return skuSaleAttrValueService.selectSkuIdByAttrSaleId(attrSaleId);
    }

}
